﻿@using Citi.GocAttributes.WebUI.Models
@model IEnumerable<RuleModel>
<table class="table table-bordered table-striped tablesorter-blue">
    <thead>
        <tr>
            <th style="width: 70px">
                Order
            </th>
            <th style="width: 20%">
                Name
            </th>
            <th style="max-width: 50%">
                Conditions
            </th>
            <th style="width: 340px;">
                Results
            </th>
            <th style="width: 40px;">
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Order)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                    <br />
                </td>
                <td>
                    @foreach (var ruleCondition in item.RuleConditions)
                    {
                        @(ruleCondition.Type.GetDescription())<text>: </text>
                        @(ruleCondition.Value ?? (ruleCondition.ManagedSegment != null
                                                      ? ruleCondition.ManagedSegment.Description
                                                      : ruleCondition.Function.Description))
                        <br />
                    }
                </td>
                <td>
                    @foreach (var ruleResult in item.LastRuleResults)
                    {
                        @(string.Concat(ruleResult.TypeRuleResult.Type.GetDescription(), ": ", ruleResult.TypeRuleResult.Value))    
                        <br />
                    }
                </td>
                <td>
                    @Ajax.ActionLink("Edit", "Form",
                                     new { id = item.Id },
                                     new AjaxOptions { UpdateTargetId = "ruleForm", OnBegin = "openCloseRuleDialog" },
                                     new { @class = "icon-pencil" })
                    @Ajax.ActionLink("Delete", "Delete",
                                     new { id = item.Id }, new AjaxOptions { UpdateTargetId = "ruleList", Confirm = "Are you sure?" },
                                     new { @class = "icon-remove" })
                    @Ajax.ActionLink("Details", "Form",
                                     new { id = item.Id, Details = true },
                                     new AjaxOptions { UpdateTargetId = "ruleForm", OnBegin = "openCloseRuleDialog" },
                                     new { @class = "icon-eye-open" })
                </td>
            </tr>
        }
    </tbody>
</table>
@Html.Partial("~/Views/PartialView/Pager.cshtml", new PagerModel { ColumnStartIndex = 1, ColumnStartOrder = PagerModel.Order.Descending })
